package com.qqqq.web;

import com.qqqq.core.AjaxResult;
import com.qqqq.core.BaseHttpServlet;
import com.qqqq.dao.impl.StudentDaoImpl;
import com.qqqq.domain.SignIn;
import com.qqqq.service.StudentService;
import com.qqqq.service.impl.StudentServiceImpl;
import com.qqqq.utils.RequestUtils;
import com.qqqq.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/select_sign")
public class SelectSignInServlet extends BaseHttpServlet {
    private StudentService studentService = new StudentServiceImpl(new StudentDaoImpl());

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SignIn signIn = RequestUtils.getReqJsonBody(req, SignIn.class);
        int pageNum = req.getParameter("pageNum") == null ? 1 : Integer.parseInt(req.getParameter("pageNum"));
        int pageSize = req.getParameter("pageSize") == null ? 10 : Integer.parseInt(req.getParameter("pageSize"));
        executeBusiness(resp, response -> {
            ResponseUtils.responseJson(resp, AjaxResult.success(studentService.pageSignIn(signIn.getStuId(), pageNum, pageSize)));
        });
    }
}
